package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

public class OrdersController {
        public Object createOrders(HttpServletRequest request){
        String userid = request.getParameter("userId");
        Integer businessid = Integer.valueOf(request.getParameter("businessId"));
        Integer daid = Integer.valueOf(request.getParameter("daId"));
        Double orderTotal = Double.valueOf(request.getParameter("orderTotal"));
        Orders orders = new Orders();
        orders.setUserId(userid);
        orders.setBusinessId(businessid);
        orders.setDaId(daid);
        orders.setOrderTotal(orderTotal);
        OrdersService ordersService = new OrdersServiceImpl();
        int a = ordersService.screateOrders(orders);
        return a;
    }

    public Object getOrdersById(HttpServletRequest request){
        Orders orders = new Orders();
        Integer orderid = Integer.valueOf(request.getParameter("orderId"));
        OrdersService ordersService = new OrdersServiceImpl();
        orders = ordersService.sgetOrdersById(orderid);
        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request){
        List<Orders> list = new ArrayList<>();
        String userid = request.getParameter("userId");
        OrdersService ordersService = new OrdersServiceImpl();
        list = ordersService.slistOrdersByUserId(userid);
        return list;
    }
}
